import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/main/app_bar.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/gender_select_widget.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/show_date_wheel.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/login/text_field.dart';
import 'package:flutter_eve_plugin/constants/icon_font.dart';
import 'package:flutter_eve_plugin/model/health/user_info.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/login/actions.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/store_vm/ye_xiu/login/main.dart';
import 'package:flutter_eve_plugin/store_vm/ye_xiu/main.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class LoginBirthdayPage extends StatefulWidget {
  final String title;

  LoginBirthdayPage({Key key, this.title}) : super(key: key);

  @override
  _LoginBirthdayPageState createState() => _LoginBirthdayPageState();
}

class _LoginBirthdayPageState extends State<LoginBirthdayPage> {
  String _nickName = '';

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(converter: (store) {
      return AppStateViewModel(
          state: store.state,
          yeXiuStateViewModel: YeXiuStateViewModel(
              loginStateViewModel: LoginStateViewModel(confirm: () {
            int birthday = store.state.yeXiuState.loginState.birthday;
            int sex = store.state.yeXiuState.loginState.sex;
            String mobile = store.state.yeXiuState.loginState.phone;
            UserInfoModelReq req = UserInfoModelReq();
            req.nickname = _nickName;
            req.birthday = birthday;
            req.sex = sex;
            req.mobile = mobile;
            inputNickName(store, _nickName);
            store.dispatch(birthdayConfirm(context, req));
          })));
    }, builder: (context, vm) {
      bool isConfirm = false;
      int birthday = vm.state.yeXiuState.loginState.birthday ?? 0;
      int sex = vm.state.yeXiuState.loginState.sex ?? 2;
      if (_nickName.length > 0 && birthday > 0 && sex > 0) {
        isConfirm = true;
      }
      return GestureDetector(
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: Scaffold(
          backgroundColor: Colors.white,
          appBar: buildAppBar(context,
              type: FigureIP.YE_XIU, colors: [Colors.white, Colors.white]),
          body: SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                  padding:
                      EdgeInsets.only(left: setRatio(30), top: setRatio(20)),
                  child: Text(
                    '让我们更了解你',
                    style: TextStyle(
                        fontSize: setTextSp(24),
                        color: Color((0xFF333333)),
                        fontWeight: FontWeight.bold),
                  ),
                ),
                SizedBox(
                  height: setRatio(70),
                ),
                Container(
                  margin:
                      EdgeInsets.only(left: setRatio(29), right: setRatio(29)),
                  decoration: ShapeDecoration(
                      shape: UnderlineInputBorder(
                          borderSide: BorderSide(
                              color: Color(0xFFE5E5E5),
                              style: BorderStyle.solid,
                              width: setRatio(1)))),
                  child: ITextField(
                    inputText: _nickName,
                    deleteIcon: Icon(
                      IconFont.CLEAR,
                      size: setRatio(18),
                      color: Color(0xFFCCCCCC),
                    ),
                    inputBorder: InputBorder.none,
                    keyboardType: ITextInputType.text,
                    hintText: '输入昵称',
                    hintStyle: TextStyle(color: Color(0xFFC2C2C2)),
                    textStyle: TextStyle(color: Color(0xFF333333)),
                    fieldCallBack: (content) {
                      _nickName = content;
                    },
                  ),
                ),
                SizedBox(
                  height: setRatio(10),
                ),
                ShowDateWidget(),
                SizedBox(
                  height: setRatio(16),
                ),
                GenderSelectWidget(),
                SizedBox(
                  height: setRatio(55),
                ),
                GestureDetector(
                  onTap: isConfirm
                      ? vm.yeXiuStateViewModel.loginStateViewModel.confirm
                      : null,
                  child: Container(
                    width: setRatio(315),
                    height: setRatio(46),
                    margin: EdgeInsets.only(left: setRatio(30)),
                    decoration: isConfirm
                        ? BoxDecoration(
                            borderRadius:
                                BorderRadius.all(Radius.circular(setRatio(5))),
                            gradient: LinearGradient(
                                colors: [Color(0xFF0386FF), Color(0xFF03AAFF)],
                                begin: Alignment(0.5, 0),
                                end: Alignment(0.5, 1)))
                        : BoxDecoration(
                            color: Color(0xFFD8D8D8),
                            borderRadius:
                                BorderRadius.all(Radius.circular(setRatio(5))),
                          ),
                    child: Center(
                      child: Text(
                        '确认',
                        style: TextStyle(
                            color: Colors.white, fontSize: setTextSp(17)),
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
        ),
      );
    });
  }
}
